!function(a) {
    function b() {
        return !1;
    }
    a.fn.contextmenu = function(c) {
        function u(a) {
            var b;
            if (d && d == a.name) return !1;
            for (b in g) v(b, !a.disable);
            for (b = 0; b < a.items.length; b++) v(a.items[b], a.disable);
            d = a.name;
        }
        function v(a, b) {
            var c = g[a];
            c.className = (c.disable = c.lastChild.disabled = b) ? "b-m-idisable" : "b-m-item";
        }
        function w(b, c) {
            e = c, s.call(f.cmroot, {
                left: b.pageX,
                top: b.pageY
            }, 0), a(document).one("mousedown", t);
        }
        var d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, x, y, z;
        return c = a.extend({
            alias: "cmroot",
            width: 150
        }, c), d = null, e = null, f = {}, g = {}, h = {}, i = [], j = "<div class='b-m-$[type]' unselectable=on><nobr unselectable=on><img src='$[icon]' align='absmiddle'/><span unselectable=on>$[text]</span></nobr></div>", 
        k = a("<div/>").addClass("b-m-mpanel").attr("unselectable", "on").css("display", "none"), 
        l = a("<div/>").addClass("b-m-item").attr("unselectable", "on"), m = a("<div/>").addClass("b-m-split"), 
        n = function(c) {
            return f[c.alias] = this, this.gidx = c.alias, this.id = c.alias, c.disable && (this.disable = c.disable, 
            this.className = "b-m-idisable"), a(this).width(c.width).click(b).mousedown(b).appendTo(a("body")), 
            c = null, this;
        }, o = function(a) {
            var b = this;
            return b.title = a.text, b.idx = a.alias, b.gidx = a.gidx, b.data = a, b.innerHTML = j.replace(/\$\[([^\]]+)\]/g, function() {
                return a[arguments[1]];
            }), a.disable && (b.disable = a.disable, b.className = "b-m-idisable"), a.items && (b.group = !0), 
            a.action && (h[a.alias] = a.action), g[a.alias] = b, b = a = null, this;
        }, p = function(c, d) {
            var i, g = null;
            for (i = 0; i < d.length; i++) "splitLine" == d[i].type ? g = m.clone()[0] : (d[i].gidx = c, 
            "group" == d[i].type ? (n.apply(k.clone()[0], [ d[i] ]), arguments.callee(d[i].alias, d[i].items), 
            d[i].type = "arrow", g = o.apply(l.clone()[0], [ d[i] ])) : (d[i].type = "ibody", 
            g = o.apply(l.clone()[0], [ d[i] ]), a(g).click(function() {
                return this.disable || (a.isFunction(h[this.idx]) && h[this.idx].call(this, e), 
                t()), !1;
            })), a(g).bind("contextmenu", b).hover(q, r)), f[c].appendChild(g), g = d[i] = d[i].items = null;
            c = d = null;
        }, q = function() {
            var c, d;
            return this.disable ? !1 : (t.call(f[this.gidx]), this.group && (c = a(this).offset(), 
            d = a(this).outerWidth(), s.apply(f[this.idx], [ c, d ])), this.className = "b-m-ifocus", 
            !1);
        }, r = function() {
            return this.disable ? !1 : (this.group || (this.className = "b-m-item"), !1);
        }, s = function(b, c) {
            var d = a("body").width(), e = document.documentElement.clientHeight, f = a(this).outerWidth(), g = a(this).outerHeight();
            b.left = b.left + c + f > d ? b.left - f < 0 ? 0 : b.left - f : b.left + c, b.top = b.top + g > e ? b.top - g + (c > 0 ? 25 : 0) < 0 ? 0 : b.top - g + (c > 0 ? 25 : 0) : b.top, 
            a(this).css(b).show(), i.push(this.gidx);
        }, t = function() {
            var b, a = null;
            for (b = i.length - 1; b >= 0 && i[b] != this.gidx; b--) a = i.pop(), f[a].style.display = "none", 
            g[a] && (g[a].className = "b-m-item");
        }, x = a("#" + c.alias), y = null, 0 == x.length ? (y = n.apply(k.clone()[0], [ c ]), 
        y.applyrule = u, y.showMenu = w, p(c.alias, c.items)) : y = x[0], z = a(this).each(function() {
            return a(this).bind("contextmenu", function(b) {
                var d = c.onContextMenu && a.isFunction(c.onContextMenu) ? c.onContextMenu.call(this, b) : !0;
                return d && (c.onShow && a.isFunction(c.onShow) && c.onShow.call(this, y), y.showMenu(b, this)), 
                !1;
            });
        }), c.rule && u(c.rule), k = l = m = j = n = o = null, p = q = r = null, z;
    };
}(jQuery);